import { RouteConfig } from '../routes'
import { HookItem, InterviewItem } from '../types'

// Hook内容导入
import { useLocalStorageContent } from '../content/hooks/useLocalStorage'
import { useDebounceContent } from '../content/hooks/useDebounce'
import { useLockContent } from '../content/hooks/useLock'

// 面试题内容导入
import { debounceContent } from '../content/interviews/debounce'
import { throttleContent } from '../content/interviews/throttle'

// Hook内容映射
const hookContentMap: Record<string, any> = {
  'useLocalStorage': useLocalStorageContent,
  'useDebounce': useDebounceContent,
  'useLock': useLockContent
}

// 面试题内容映射
const interviewContentMap: Record<string, any> = {
  'debounce': debounceContent,
  'throttle': throttleContent
}

// 加载Hook内容
export const loadHookContent = async (route: RouteConfig): Promise<HookItem> => {
  const content = hookContentMap[route.id]
  
  if (!content) {
    throw new Error(`Hook内容未找到: ${route.id}`)
  }

  return {
    id: route.id,
    title: route.title,
    description: route.description,
    category: route.category,
    tags: route.tags,
    code: content.code,
    explanation: content.explanation,
    usage: content.usage,
    practice: content.practice
  }
}

// 加载面试题内容
export const loadInterviewContent = async (route: RouteConfig): Promise<InterviewItem> => {
  const content = interviewContentMap[route.id]
  
  if (!content) {
    throw new Error(`面试题内容未找到: ${route.id}`)
  }

  return {
    id: route.id,
    title: route.title,
    description: route.description,
    category: route.category,
    difficulty: route.difficulty!,
    tags: route.tags,
    problem: content.problem,
    solution: content.solution,
    explanation: content.explanation,
    practice: content.practice
  }
}

// 预加载所有内容
export const preloadAllContent = async () => {
  // 这里可以添加预加载逻辑
  console.log('所有内容已预加载')
}
